package com.fz.song.service.impl;


import com.fz.song.dao.BlogLabelMapper;
import com.fz.song.pojo.BlogLabel;
import com.fz.song.pojo.BlogType;
import com.fz.song.service.IBlogLableService;
import com.fz.song.util.ResultObj;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogLableServiceImpl implements IBlogLableService {


    @Autowired
    private BlogLabelMapper blogLabelMapper;

    @Override
    public PageInfo<BlogLabel> getBlogLableListData(Integer page, int limit) {
        PageHelper.startPage(page, limit);
        List<BlogLabel> userList = blogLabelMapper.getBlogTypeListData();
        PageInfo<BlogLabel> pageInfo = new PageInfo<BlogLabel>(userList);
        return pageInfo;
    }

    @Override
    public BlogLabel getBlogLableByid(String id) {
        return blogLabelMapper.selectByPrimaryKey(id);
    }

    @Override
    public ResultObj saveBlogLabel(BlogLabel blogLabel) {
        int i = blogLabelMapper.insertSelective(blogLabel);
        if (i == 1) {
            return ResultObj.ok("保存成功");
        }
        return ResultObj.error("保存失败");
    }

    @Override
    public ResultObj updateBlogLabel(BlogLabel blogLabel) {
        int i = blogLabelMapper.updateByPrimaryKeySelective(blogLabel);
        if (i == 1) {
            return ResultObj.ok("保存成功");
        }
        return ResultObj.error("保存失败");
    }

    @Override
    public ResultObj delBlogLabel(String id) {
        BlogLabel blogLabel = blogLabelMapper.selectByPrimaryKey(id);
        blogLabel.setDel(1);
        int i = blogLabelMapper.updateByPrimaryKeySelective(blogLabel);
        if (i == 1) {
            return ResultObj.ok("删除成功");
        }
        return ResultObj.error("删除失败");
    }

    @Override
    public List<BlogLabel> getBlogLableList() {
        List<BlogLabel> blogTypeListData = blogLabelMapper.getBlogTypeListData();
        return blogTypeListData;
    }
}
